﻿using System.Net.Sockets;
using System.Net;
using System.Text;

namespace Server
{
    internal class ServerStart
    {
        static void Main(string[] args)
        {
            CreateBasicServer();
        }


        static void CreateBasicServer()
        {
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPAddress iPAddress = new IPAddress(new byte[] { 127, 0, 0, 1 });
            EndPoint pt = new IPEndPoint(iPAddress, 17666);

            socket.Bind(pt);
            socket.Listen(100);
            Console.WriteLine("Server Start....");
            Socket skt = socket.Accept();

            string msg = "连接成功....";
            byte[] bytes = Encoding.UTF8.GetBytes(msg);
            skt.Send(bytes);

            //接受的数据缓存
            byte[] dataRcv = new byte[1024];
            int lenRcv= skt.Receive(dataRcv);

            string msgRcv=Encoding.UTF8.GetString(dataRcv,0,lenRcv);

            Console.WriteLine("Rcv Server Data:"+msgRcv);

            Console.ReadKey();

        }
    }
}